package com.erainm.sort;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Created by erainm on 2021/08/14/5:50 下午.
 *
 * @Description:  排序driver
 */
public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        args = new String[] { "/Users/erainm/Documents/application/dev/workSpace/fed-e-task-01-01/homework01/data",
                "/Users/erainm/Documents/application/dev/workSpace/fed-e-task-01-01/homework01/output-step1" };

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "SortDriver");
        job.setJarByClass(SortDriver.class);

        // 设置mapper 和 reducer类
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);

        // 设置输出类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);

        // 设置输入输出路径参数
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);
    }
}
